package com.github_dididipapa.common.validator;


import com.github_dididipapa.common.transmonitor.IsShowStatus;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import java.util.HashSet;
import java.util.Set;

public class IsShowStatusConstraintValidator implements ConstraintValidator<IsShowStatus, Integer> {
    private final Set<Integer> set = new HashSet<>();
    @Override
    public void initialize(IsShowStatus constraintAnnotation) {
        int[] values = constraintAnnotation.values();
        for (int value : values) {
            set.add(value);
        }
    }

    //判断是否校验成功
    @Override
    public boolean isValid(Integer value, ConstraintValidatorContext constraintValidatorContext) {
        return set.contains(value);
    }
}
